﻿using BCCommon;
using BCDto.OA.Reimbursement;
using BCService.OA.ReimbursementRecord;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BlackCoffeeRESTful.Controllers.Management.OA.ReimbursementRecord
{
    /// <summary>
    /// 报销记录信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class ReimbursementRecordController : ManagementBaseController
    {
        private readonly IReimbursementRecordService reimbursementRecordService;

        public ReimbursementRecordController(IReimbursementRecordService reimbursementRecordService)
        {
            this.reimbursementRecordService = reimbursementRecordService;
        }

        /// <summary>
        /// 分页获取OA报销我的申请记录(列表)
        /// </summary>
        /// <param name="departmentName">部门名称</param>
        /// <param name="adminName">员工名称</param>
        /// <param name="start">申请时间开始</param>
        /// <param name="end">申请时间结束</param>
        /// <param name="ascending">是否升序排序</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页页数</param>
        /// <param name="sortName">排序字段</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<ReimbursementRecordDto>), 200)]
        public IActionResult MyApplied([FromQuery(Name = "department_name")]string departmentName,
            [FromQuery(Name = "admin_name")]string adminName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "sort_name")]string sortName,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.reimbursementRecordService.Query(this.Admin.IsSystemAccount ? new BCDto.MySql.Admin.AdminDto { AdminId = 0 } : this.Admin, departmentName, adminName, start, end, ascending, pageIndex, pageSize, sortName, false));
        }

        /// <summary>
        /// 分页获取OA报销我的审批记录(列表)
        /// </summary>
        /// <param name="departmentName">部门名称</param>
        /// <param name="adminName">员工名称</param>
        /// <param name="start">申请时间开始</param>
        /// <param name="end">申请时间结束</param>
        /// <param name="ascending">是否升序排序</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页页数</param>
        /// <param name="sortName">排序字段</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<ReimbursementRecordDto>), 200)]
        public IActionResult MyApproved([FromQuery(Name = "department_name")]string departmentName,
            [FromQuery(Name = "admin_name")]string adminName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "sort_name")]string sortName,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.reimbursementRecordService.Query(this.Admin, departmentName, adminName, start, end, ascending, pageIndex, pageSize, sortName, this.Admin.IsSystemAccount ? false : true));
        }
    }
}